package com.tuju.currency.view.home

import android.os.Bundle
import android.os.Handler
import androidx.recyclerview.widget.LinearLayoutManager
import com.tuju.currency.R
import com.tuju.currency.adapter.HistoryAdapter
import com.tuju.currency.base.BaseFragment
import kotlinx.android.synthetic.main.fragment_history.view.*

class HistoryFragment : BaseFragment() {

    lateinit var adapter: HistoryAdapter
    private var mIsPrepared: Boolean = false
    private var mIsFirst = true

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        initView()
        mIsPrepared = true
        loadData()
    }

    override fun setContent(): Int {
        return R.layout.fragment_history
    }

    private fun initView() {
        adapter = HistoryAdapter()
        contentView.rv_history.layoutManager = LinearLayoutManager(context)
        contentView.rv_history.adapter = adapter
    }

    override fun loadData() {
        if (!mIsPrepared || isHidden || !mIsFirst) {
            return
        }
        showEmpty()
//        adapter.add("张三")
//        adapter.add("李四")
//        adapter.add("王五")
//        adapter.notifyDataSetChanged()
//        showContentView()
//        mIsFirst = false
    }

    override fun onRefresh() {
        Handler().postDelayed({
            showEmpty()
        },1000)
    }

    companion object {
        fun newInstance(url: String): HistoryFragment {
            val bundle = Bundle()
            bundle.putString("url", url)
            val fragment = HistoryFragment()
            fragment.arguments = bundle
            return fragment
        }
    }
}